<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>管理系统</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  {:widget_st('layui','css')}
  {:widget_st('admin','css')}
</head>
{:do_action('admin_head')}
<body>

  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-card-body">
          <div class="layui-row layui-col-space15">
              <div class="layui-col-md12">
                  <div class="layui-card">
                      <form class="layui-form info_tj" method="post">
                        <div class="layui-row layui-col-space12 layui-form-item">
                          <div class="layui-col-lg12">
                              <textarea name="sql"  style='width:100%;height:500px;border:1px solid #ccc;font-size:14px;'  >{$sql}</textarea>
                          </div>
                        </div>
                        
                       
      
                        <div class="layui-form-item">
                            <div style='margin-top:20px;text-align:center;'>
<!--                              <span class="layui-btn  tijiao" lay-submit="" lay-filter="component-form-element">执行SQL</span>-->
                              <a class="layui-btn layui-btn-primary" href='/admin/Mysql/index'>返回上一级</a>
                            </div>
                        </div>
                      </form>
                  </div>            
              </div>
          </div>

      </div>
    </div>
  </div>
  {:widget_st('jq','js')}
  {:widget_st('layui','js')}
  {:widget_st('common','js')} 

  <script>
  layui.use(['element'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element;

    function utoa(str) {
      return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
          return String.fromCharCode('0x' + p1);
        }));
    }

    $(".tijiao").on("click",function(){
      var index = layer.load(1);
      var sql = $("textarea[name='sql']").val();
      var encryptedSql = utoa(sql);
      // 检查加密后的SQL大小
      if (encryptedSql.length > 10485760) { // 假设限制为10MB
        layer.msg("SQL语句太长,请减少内容后重试", {icon: 2});
        return;
      }
      $.ajax({
          type:'post',
          url:"{:url('mysql/restore',['t'=>'exec'])}",
          data:{sql:encryptedSql},
          dataType:'json',
          success:function(res){
            layer.close(index);
            if(res.result==1){
              layer.msg("执行SQL成功", {icon: 1});
            }else{
              layer.msg("执行SQL失败", {icon: 2});
            }
            
          }
      })

    })
 
   
  });
  </script>
</body>
</html>
{:do_action('admin_js')}
